import javax.swing.*;

public class CheckEmptyFive extends CheckEmptyFour {
    JTextField txtS5;

    //tf为待检查的文本框
    public CheckEmptyFive(JTextField t1, JTextField t2, JTextField t3, JTextField t4, JTextField t5) {
        super(t1, t2, t3, t4);
        txtS5 = t5;
    }

    //检查文本框中是否已输入数据
    @Override
    public boolean check(int i) {
        //仅判断是否文本框为空
        if (i == 0) {
            if (txtS1.getText().length() == 0 || txtS2.getText().length() == 0 || txtS3.getText().length() == 0 || txtS4.getText().length() == 0 || txtS5.getText().length() == 0) {
                JOptionPane.showMessageDialog(null, "请先在文本框中输入数据！");
                return false;
            } else
                return true;
            //判断是否为空、负数、数字
        } else {
            String regex = "[^1234567890.]";
            if (txtS1.getText().length() == 0 || txtS2.getText().length() == 0 || txtS3.getText().length() == 0 || txtS4.getText().length() == 0 || txtS5.getText().length() == 0) {
                JOptionPane.showMessageDialog(null, "请先在文本框中输入数据！");
                return false;
                //正则表达式,输入必须为数字
            } else if (txtS1.getText().matches(regex) || txtS2.getText().matches(regex) || txtS3.getText().matches(regex) || txtS4.getText().matches(regex) || txtS5.getText().matches(regex)) {
                JOptionPane.showMessageDialog(null, "必须输入数字，请重新输入数据！");
                return false;
            } else if (Float.parseFloat(txtS1.getText()) < 0 || Float.parseFloat(txtS2.getText()) < 0 || Float.parseFloat(txtS3.getText()) < 0 || Float.parseFloat(txtS4.getText()) < 0 || Float.parseFloat(txtS5.getText()) < 0) {
                JOptionPane.showMessageDialog(null, "不该为负值，请重新输入数据！");
                return false;
            } else
                return true;
        }
    }
}